package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserAccountService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    DtsUserService userService;

    @Autowired
    DtsUserAccountService userAccountService;

    @RequestMapping("/list")
    public Object list(
            @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(name = "limit",required = false,defaultValue = "20") Integer limit,
            String username,
            String mobile,
            @RequestParam(name = "sort",required = false,defaultValue = "add_time") String sort,
            @RequestParam(name = "order",required = false,defaultValue = "desc") String order){

        IPage<DtsUser> iPage = userService.findPage(page,limit,username,mobile,sort,order);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }

    @RequestMapping("/detailApprove")
    public Object detailApprove(Integer id){
        DtsUserAccount byId = userAccountService.findById(id);
        Map<String,Object> data = new HashMap<>();
        data.put("id",byId.getId());
        data.put("userId",byId.getUserId());
        data.put("remainAmount",byId.getRemainAmount());
        data.put("totalAmount",byId.getTotalAmount());
        data.put("createTime",byId.getCreateTime());
        data.put("modifyTime",byId.getModifyTime());
        data.put("settlementRate",byId.getSettlementRate());
        data.put("status",byId.getStatus());
        return ResponseUtil.ok(data);

    }

    @RequestMapping("/approveAgency")
    public Object approveAgency(){

        return ResponseUtil.ok();
    }

}
